package com.tool_stdy.thread;

import java.util.concurrent.*;

/**
 * Created by yan_li on 2016/1/22.
 */
public class TestExecPool {
    private static ExecutorService exec = Executors.newFixedThreadPool(5);
    private static CompletionService pool =new ExecutorCompletionService(exec);
    public static void main(String[] args) {
       for(int i=0;i<5;i++){
           final int j =i;
           pool.submit(new Callable() {
               @Override
               public Object call() throws Exception {
                   Thread.sleep(20);
                   System.out.println(Thread.currentThread().getName()+"-->"+j);
                   return "";
               }
           });
       }
        exec.shutdown();
    }
}
